import { useState } from "react"

export const useArray =<T> (persons:T[])=>{
  const [value, setValue] = useState(persons)
  return{
    value,
    setValue,
    add:(person:T)=>{ setValue([...value,person])},
    removeIndex:(index:number)=>{ 
      const persons = [...value]
      persons.splice(index,1)
      setValue(persons)
    },
    clear:()=>setValue([])
  }
}